
package com.zsrt.day20170419.ch02;

import org.junit.Before;
import org.junit.Test;

import com.zsrt.utils.ArrayUtil;

public class CompanyDaoTest {
	
	CompanyDao companyDaoImpl = new CompanyDaoImpl();
	Programmer[] programmers = new Programmer[10];
	
	
	@Before
	public void before(){
		
		Programmer j1 = new JavaProgram("何小强",'男',12000,"高级工程师");
		Programmer j2 = new JavaProgram("罗智壕",'男',9000,"初级工程师");
		
		Programmer p1 = new PHPProgram("贾梦菊",'女',10000,"初级工程师");
		Programmer p2 = new PHPProgram("张嘉源",'女',8000,"初级工程师");
		
		programmers[0] = j1;
		programmers[1] = j2;
		programmers[2] = p1;
		programmers[3] = p2;
	}
	
	/**
	 * 测试增加程序员操作
	 * @throws Exception
	 */
	@Test
	public void addTest() throws Exception {
		
		Company hualai = new Company("华莱",programmers);
		Programmer programmer = new JavaProgram("周驰", '男', 10000, "中级工程师");
		boolean b = companyDaoImpl.addProgram(hualai, programmer);
		
		System.err.println(b);
		ArrayUtil.StudentEntity(programmers);
	}

	/**
	 * 测试根据名字删除程序员
	 * @throws Exception
	 */
	@Test
	public void deleteTest() throws Exception {
		Company hualai = new Company("华莱", programmers);
		
		String dname= "何小强";
		boolean b = companyDaoImpl.deleteProByName(hualai, dname);
		System.err.println(b);
		
	}
	
	/**
	 * 测试根据性别删除程序员
	 * @throws Exception
	 */
	@Test
	public void deleteBySexTest() throws Exception {
		
		Company hualai =new Company("华莱", programmers);
		//要删除的程序员的性别
		char dsex = '男';
		Programmer[] result = companyDaoImpl.deleteProBySex(hualai, dsex );
		System.out.println("根据性别 =" + dsex +"删除以后的程序员数组为：");
		ArrayUtil.StudentEntity(result);
		
	}
	
	/**
	 * 把所有的女程序员的工资增加1000块
	 * @throws Exception
	 */
	@Test
	public void updateSalaryBySexTest() throws Exception {
		
		Company hualai =new Company("华莱", programmers);
		
		//要查询的程序员性别
		char dsex = '女';
		//要增长的工资幅度
		int addNum = 1000;
		Programmer[] result = companyDaoImpl.updateSalaryBySex(hualai, dsex, addNum);
		
		ArrayUtil.StudentEntity(result);
		
	}
	
	/**
	 * 查询所有工资在10000以上的程序员
	 * @throws Exception
	 */
	@Test
	public void searchBySalaryTest() throws Exception {
		Company hualai =new Company("华莱", programmers);
		
		//要查询的工资
		int findSalary = 10000;
		Programmer[] result = companyDaoImpl.searchBySalary(hualai, findSalary );
		
		ArrayUtil.StudentEntity(result);
		
	}
	
	/**
	 * 查询所有工资在10000以上且是初级工程师的程序s 判定为 ：　中级程序员
	 * @throws Exception
	 */
	@Test
	public void judgeLevelBySalaryTest() throws Exception {
		Company hualai =new Company("华莱", programmers);
		
		//要查询的工资
		int findSalary = 10000;
		//判定工程师的级别
		String dLevel  = "中级工程师";
		//性别随意设定
		Programmer programmer = new JavaProgram(null, '0', findSalary, dLevel);
		//System.out.println(programmer);
		Programmer[] result = companyDaoImpl.judgeLevelBySalary(hualai, programmer  );
		
		ArrayUtil.StudentEntity(result);
		
		
	}
	
}
